﻿/*
 * 文件名称：
 * 程序员：wangyun
 * 创建时间：2008/06/16
 * 
 * 功能说明：数据字典类别管理页面
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Config_ChoiceType : System.Web.UI.Page
{
    protected string action = "";
    protected int TypeID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断

        action = NetRequest.GetQueryString("Action");
        TypeID = NetRequest.GetQueryInt("TypeID");

        if (!IsPostBack)
        {
            switch (action)
            {
                case "Add": break;
                case "Modify":
                    BindData();
                    btnSumbit.Text = "更新";
                    break;
                case "Delete":
                    BindData();
                    btnSumbit.Text = "删除";
                    btnSumbit.Attributes.Add("onclick", "return confirm('确定要删除吗？一旦删除，将删除该类别下的所有选项！');");
                    break;
            }
        }
    }

    private void BindData()
    {
        Whir.BLL.Whir_ChoiceType bll = new Whir.BLL.Whir_ChoiceType();
        Whir.Model.Whir_ChoiceType model = bll.GetModel(TypeID);
        txtChoiceTypeMark.Text = model.choiceTypeMark;
    }

    protected void btnSumbit_Click(object sender, EventArgs e)
    {
        Whir.BLL.Whir_ChoiceType bll = new Whir.BLL.Whir_ChoiceType();
        Whir.Model.Whir_ChoiceType model;
        switch (action)
        {
            case "Add":
                model = new Whir.Model.Whir_ChoiceType();
                model.choiceTypeMark = txtChoiceTypeMark.Text.Trim();
                bll.Add(model);
                break;
            case "Modify":
                model = bll.GetModel(TypeID);
                model.choiceTypeMark = txtChoiceTypeMark.Text.Trim();
                bll.Update(model);
                break;
            case "Delete":
                model = bll.GetModel(TypeID);

                //删除该类别下的信息
                Whir.BLL.Whir_Choice choiceBll = new Whir.BLL.Whir_Choice();
                DataTable dt = Whir.SQLServerDAL.DbHelperSQL.GetDataTable("choiceID", "Whir_Choice", " choiceTypeID = " + TypeID, "");
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        choiceBll.Delete(int.Parse(row[0].ToString()));
                    }
                }

                //删除该类别
                if (model != null)
                {
                    bll.Delete(TypeID);
                }
                break;
        }

        Response.Redirect("ChoiceTypeManage.aspx");
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("ChoiceTypeManage.aspx");
    }
}
